import redis
r = redis.Redis(host="118.24.3.40",
                password="HK139bc&*",
                port=6379,db=0,
                decode_responses=True)#0-15

r2 = redis.Redis(host="118.24.3.40",
                password="HK139bc&*",
                port=6379,db=2,
                decode_responses=True)#0-15

#1、获取所有的key
#2、判断key的类型
#3、根据key的类型来使用set或者hset

for key in r.keys():
    if r.type(key) == "string":
        value = r.get(key)
        r2.set(key,value)
    elif r.type(key) == "hash":
        hash_all = r.hgetall(key)
        for k,v in hash_all.items(): #循环hash类型里面所有的k-v
            r2.hset(key,k,v)